﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace Hydra.Core
{
    internal class Parasite : IParasite, IParasiteLogger
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private IHydraService _service;

        public void Connect()
        {
            if (_service == null)
            {
                _service = DuplexChannelFactory<IHydraService>.CreateChannel(
                    new HydraCallback(),
                    new NetNamedPipeBinding(),
                    new EndpointAddress("net.pipe://localhost/" +
                        Util.GetHash(Process.GetCurrentProcess().Id)));
                log.Info("client inited.");

                _service.Register();
                log.Info("client registered.");
            }
        }

        public void Disconnect()
        {
            if (_service != null)
            {
                _service.Unregister();
                log.Info("client unregistered.");
                _service = null;
            }
        }

        public void Info(string format, params object[] objs)
        {
            throw new NotImplementedException();
        }

        public static Parasite Instance
        {
            get
            {
                // TODO:
                return null;
            }
        }
    }
}
